package T6_commite;

public class T6_commite {    
    public static void main(String[] args) {    
        ThreadB b = new ThreadB();    
        b.start();    
        synchronized (b) {     //获取对象的锁并让wait（）；
            try {    
//            	try {
//    				Thread.sleep(1000);
//    			} catch (InterruptedException e) {
//    				e.printStackTrace();
//    			}
                System.out.println("等待对象b完成计算。。。");    
                b.wait();      //主线程放弃b的锁
            } catch (InterruptedException e) {    
                e.printStackTrace();    
            }    
            System.out.println("b对象计算的总和是：" + b.total);    
        }    
    }    
}  

class ThreadB extends Thread {    
    int total = 0;    
  
    public void run() {    
        synchronized (this) {    
            for (int i = 0; i < 101; i++) {    
                total += i;    
                try {
    				Thread.sleep(10);
    			} catch (InterruptedException e) {
    				e.printStackTrace();
    			}
            }    
            notify();    
        }    
    }    
} 
